﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using DevFx.FrameWork.Resources;

namespace DevFx.FrameWork.Context
{
    /// <summary>
    /// 上下文帮助类
    /// </summary>
    public static class ContextHelper
    {

        #region 私有方法

        /// <summary>
        /// 根据指定键值从框架内部上下文中获取指定的上下文接口
        /// </summary>
        /// <param name="key">键值</param>
        /// <returns></returns>
        private static IContext GetContext(string key)
        {
            IDictionary dic = FrameContext.GetFrameContext();
            if (!dic.Contains(key))
            {
                IContext context = new DefaultContext();
                dic.Add(key, context);
            }

            return dic[key] as IContext;
        }
        #endregion

        #region 公共方法
        /// <summary>
        /// 获取上下文接口实例
        /// </summary>
        /// <returns></returns>
        public static IContext GetContext()
        {
            return GetContext(FrameworkResources.Context_CustomKey);
        }
        /// <summary>
        /// 获取存放数据库连接的上下文接口实例
        /// </summary>
        /// <returns>数据库连接上下文对象</returns>
        internal static IContext GetDBContext()
        {
            return GetContext(FrameworkResources.Context_DBKey);
        }
        #endregion
    }
}
